<ul class="submenu">
<li><?php echo $this->Html->link('View', array('controller' => 'clients', 'action' => 'index')); ?></li>
<li><?php echo $this->Html->link('New', array('controller' => 'clients', 'action' => 'add')); ?></li>
</ul>

<?php 
$userbyid = array();
foreach($users as $user): 
	$userbyid[$user['User']['id']] = $user['User'];
endforeach;
?>
<table>
    <tr>
        <th>Id</th>
        <th>Name</th>
        <th>State</th>
        <th colspan="4">Action</th>
        <th>Modified</th>
        <th>Modified By</th>
        <th>Created</th>
        <th>Created By</th>
    </tr>

    <!-- Here is where we loop through our $posts array, printing out post info -->
    <?php foreach ($clients as $key => $client): ?>
    <tr>
        <td><?php echo $key+1; ?></td>
        <td><?php echo $client['Client']['title']; ?>
        </td>
        <td><?php echo $client['Client']['publish']; ?></td>
        <td>
			<?php echo $this->Html->link('Edit',
				array('controller' => 'clients', 'action' => 'edit', $client['Client']['id'])); ?>
                </td>
        <td>       
			<?php echo $this->Form->postLink('Delete',
                array('action' => 'delete', $client['Client']['id']),
                array('confirm' => 'Are you sure?'));?>
                </td>
        <td>   
            <?php echo $this->Html->link('Add task',
				array('controller' => 'tasks', 'action' => 'add', $client['Client']['id'])); ?>
                </td>
         <td>   
             <?php echo $this->Html->link('view tasks',
				array('controller' => 'tasks', 'action' => 'index', $client['Client']['id'])); ?>
                </td>
        </td>
        <td><?php echo $client['Client']['modified']; ?></td>
        <td><?php 
		if(array_key_exists($client['Client']['modified_by'],$userbyid)):
			echo $userbyid[$client['Client']['modified_by']]['username'];
		endif;
		 ?></td>
        <td><?php echo $client['Client']['created']; ?></td>
        <td>
		
		<?php 
		if(array_key_exists($client['Client']['created_by'],$userbyid)):
			echo $userbyid[$client['Client']['created_by']]['username'];
		endif;
		 ?></td>
    </tr>
    <?php endforeach; ?>
    <?php unset($client); ?>
</table>
<?php echo $this->Paginator->numbers(array('first' => 'First page')); ?>